package com.ruoyi.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.Message;
import com.ruoyi.system.domain.Project;
import com.ruoyi.system.domain.ProjectUser;
import com.ruoyi.system.service.IMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 消息
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/message")
@RequiredArgsConstructor
@Api(tags = "消息")
public class MessageController extends BaseController {

    private final IMessageService messageService;

    @GetMapping("/list")
    @ApiOperation("查询消息列表")
    public TableDataInfo list()
    {
        startPage();
        QueryWrapper<Message> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",getUserId());
        wrapper.orderByDesc("created_time");
        List<Message> list = messageService.list(wrapper);
        return getDataTable(list);
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("查看消息详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        Message message = messageService.getById(id);
        message.setIsRead(1);
        messageService.updateById(message);
        return success(message);
    }

    @ApiOperation("删除消息")
    @PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(messageService.removeBatchByIds(Arrays.asList(ids)));
    }

}
